package uniLearn.data;

import java.util.ArrayList;

public class Units {
	//define
	public static final int ID_MAX_LENGTH = 10;
	public static final int NAME_MAX_LENGTH = 50;
		
	//variable
	private String id;
	private String name;
	
	//get method
	public String getId() {
		return id;
	}
	public String getName() {
		return name;
	}
	
	//constructor
	public Units(String id, String name) {
		if(id.isEmpty() || id.length() > ID_MAX_LENGTH) {
			//error
		}
		else if(name.isEmpty() || name.length() > NAME_MAX_LENGTH) {
			//error
		}
		
		this.id = id;
		this.name = name;
	}
	
	//override function
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Units other = (Units) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}
	@Override
	public String toString() {
		return "units [id=" + id + ", name=" + name + "]";
	}
	
	//Others Static function
	public static String[] getIdArray(ArrayList<Units> unitsList) {
		if(unitsList == null)
			return null;
		
		int size = unitsList.size();
		if(size < 1)
			return null;
		
		String[] idArr = new String[size];
		for(int i = 0; i < size; i++)
			idArr[i] = unitsList.get(i).id;
		
		return idArr;
	}
}
